import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDStageMainChapter {
	/**章节id*/
	id,
	/**前置章节*/
	preChapter,
	/**章节名称*/
	name,
	/**关卡页数*/
	stagePage,
	/**图标*/
	icon,

	/**枚举数量*/
	EnumCount
}



export class CDStageMainChapter{
	/**章节id*/
	public id: number;
	/**前置章节*/
	public preChapter: number;
	/**章节名称*/
	public name: number;
	/**关卡页数*/
	public stagePage: number;
	/**图标*/
	public icon: string;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDStageMainChapter.id: return this.id;
			case E_CDStageMainChapter.preChapter: return this.preChapter;
			case E_CDStageMainChapter.name: return this.name;
			case E_CDStageMainChapter.stagePage: return this.stagePage;
			case E_CDStageMainChapter.icon: return this.icon;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDStageMainChapter.id: this.id = v; break;
			case E_CDStageMainChapter.preChapter: this.preChapter = v; break;
			case E_CDStageMainChapter.name: this.name = v; break;
			case E_CDStageMainChapter.stagePage: this.stagePage = v; break;
			case E_CDStageMainChapter.icon: this.icon = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDStageMainChapter> = new HashMap<number, CDStageMainChapter>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDStageMainChapter[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDStageMainChapter();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].preChapter = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].stagePage = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDStageMainChapter{
		return this.datas ? this.datas.get(id) : null;
	}
}
